import { Dialog } from 'vant';
import 'vant/es/dialog/style';
import {delCart} from '@/common/api/cart'
export default{
    state:{
        cartData:'',

    },
    mutations:{
        getCart(state,data){
            state.cartData=data.reverse()
            
        },
        changeData(state,index){
                
                state.cartData.splice(index,1)
                

        }
        
    },
    getters:{

    },
    actions:{
        // 删除购物车数据
        delCart(state,parmas){
            Dialog.confirm({
                title: '标题',
                message:
                  '确认要删除购物车数据吗',
              })
                .then(() => {
                  // on confirm
                  delCart(parmas[0]).then(res=>{
                    state.commit('changeData',parmas[1])
                  })
                  
                })
                .catch(() => {
                  // on cancel
                });
              
            
        },
        

    }


}